package org.mm.proxycache.http.codec;

import org.apache.mina.common.IoAcceptor;
import org.apache.mina.common.IoSession;
import org.apache.mina.filter.codec.ProtocolCodecFactory;
import org.apache.mina.filter.codec.ProtocolDecoder;
import org.apache.mina.filter.codec.ProtocolEncoder;

public class HttpCodecFactory implements ProtocolCodecFactory
{
    
    public ProtocolDecoder getDecoder( IoSession session ) throws Exception
    {
        if ( session.getService() instanceof IoAcceptor )
        {
            return new HttpRequestDecoder();
        }
        
        return new HttpResponseDecoder();
    }
    
    public ProtocolEncoder getEncoder( IoSession session ) throws Exception
    {
        if ( session.getService() instanceof IoAcceptor )
        {
            return new HttpResponseEncoder();
        }
        
        return new HttpRequestEncoder();
    }
    
}
